/**
 * author: zhangwei
 * 角色管理列表
 */
var main = {

    init: function() {
        this.initTable();
        this.tabBind();
    },
    initTable: function() {
        var _this=this;
        loadTable();
        // 添加
        $('#btnAdd').click(function() {
            localStorage.planType = "add";
            parent.$t.goToPage(this, "/plan/manage");
        });
    },
    tabBind: function() {
        layui.use(['form'], function () {
            var form = layui.form;

            
        });
    }
}
main.init();

function loadTable() {
    layui.use('table', function(){
        var table = layui.table;
        var form = layui.form;
        table.render({
            elem: '#test'
            ,url:"/plan/queryPage"
            ,title: '角色数据表'
            ,cols: [[
                {field:'planName', title:'计划名称'}
                // ,{field:'planDesc', title:'计划描述'}
                ,{field:'joinPeopleStr', title:'参加人员'}
                // ,{field:'evaluationCriterion', title:'评价标准'}
                ,{field:'startTime', title:'开始时间', templet: function (res) {
                        return formatSimpleDate(res.startTime);
                    }}
                ,
                {field:'endTime', title:'结束时间', templet: function (res) {
                        return formatSimpleDate(res.endTime);
                    }}
                ,{field:'updateTime', title:'修改时间', templet: function (res) {
                    return formatDate(res.updateTime);
                }},{field:'userName', title:'修改人'}
                ,{field:'statusStr', title:'状态'}
                ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:200}
            ]]
            ,page: true
        });

        //监听行工具事件
        table.on('tool(test)', function(obj){
            var data = obj.data;
            if(obj.event === 'del') {
                layer.confirm('您确定要删除么', function(index){
                    var json = {"id":data.id};
                    $.ajax({
                        type:"get",
                        data:json,
                        async:false,
                        url:"/plan/delete",
                        success:function(result) {
                            if (result.code == property.successCode) {
                                successMsg("删除成功");
                                loadTable();
                            } else{
                                errorMsg(result.msg);
                            }
                        },
                        error:function(result) {
                            errorMsg("系统异常");
                        }
                    });
                    layer.close(index);
                });
            } else if (obj.event === 'edit'){
                localStorage.planType = "edit";
                localStorage.planId = data.id;
                parent.$t.goToPage(this, "/plan/manage");
            }else if (obj.event === 'detail'){
                localStorage.planType = "detail";
                localStorage.planId = data.id;
                parent.$t.goToPage(this, "/plan/manage");
            }
        });
    });
}

